#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <QuickLook/QuickLook.h>
#include "OpenDDSFile.h"
#include "DDSDrawToImage.h"

/* -----------------------------------------------------------------------------
    Generate a thumbnail for file

   This function's job is to create thumbnail for designated file as fast as possible
   ----------------------------------------------------------------------------- */

OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize)
{   
	DDSFile *file = DDSOpenFile(url);
	if (!file) return -1;
	
	CGSize size = QLThumbnailRequestGetMaximumSize(thumbnail);
	
	CGImageRef result = DDSCreateImage(file, (CFIndex) size.width, (CFIndex) size.height);
	DDSDestroy(file);
	if (!result)
		return -1;
	
	QLThumbnailRequestSetImage(thumbnail, result, NULL);
	
    return noErr;
}

void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail)
{
    // implement only if supported
}
